package com.hy.dao.impl;
/*
 * @ Date: 2024/5/14 22:32
 * @ Description: ParametertableDaoImpl
 **/

import com.hy.bean.Parametertable;
import com.hy.dao.ParametertableDao;
import com.hy.exception.BizException;
import com.hy.utils.DBManager;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.util.List;

public class ParametertableDaoImpl implements ParametertableDao {
    private QueryRunner qr = new QueryRunner();
    @Override
    public Parametertable queryById(Integer id) {
        return null;
    }

    @Override
    public List<Parametertable> queryAllByLimit() {
        Connection conn = null;
        try {
            conn = DBManager.getConnection();
            String sql = "select * from parametertable";
            List<Parametertable> query = qr.query(conn, sql, new BeanListHandler<Parametertable>(Parametertable.class));
            return query;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }finally {

        }
    }

    @Override
    public long count(Parametertable parametertable) {
        return 0;
    }

    @Override
    public Boolean insert(Parametertable parametertable) {
        try {
            Connection conn = DBManager.getConnection();
            String sql = "insert into parametertable values(null,?,?,?,?)";
            return qr.update(conn,sql,parametertable.getParamtype(),parametertable.getParamvalue(),parametertable.getDisvalue(),parametertable.getRemark()) >0;
        } catch (Exception e) {
            throw new BizException("dao出错啦",e);
        }
    }

    @Override
    public Boolean update(Parametertable parametertable) {
        try {
            Connection conn = DBManager.getConnection();
            String sql = "update parametertable set paramtype=?,paramvalue=?,disvalue=?,remark=? where id = ?";
            return qr.update(conn,sql,parametertable.getParamtype(),parametertable.getParamvalue(),parametertable.getDisvalue(),parametertable.getRemark(),parametertable.getId()) >0;
        } catch (Exception e) {
            throw new BizException("dao出错啦",e);
        }
    }

    @Override
    public int deleteById(Integer id) {
        return 0;
    }
}
